using System;
using AntEater.ComponentModel.Validation;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace AntEater.ComponentModel.BuildElements
{
    /// <summary>
    /// Provides the Output build element.
    /// </summary>
    [Serializable]
    [BuildElement("Output")]
    [Icon(typeof(OutputBuildElement), "AntEater.ComponentModel.Resources.Output.ico")]
    public class OutputBuildElement : BuildElementBase
    {

        /// <summary>
        /// Initializes a new instance of the <see cref="T:OutputBuildElement"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        public OutputBuildElement(BuildFileDefinition context)
            : base(context) {
        }

        private string _condition;

        /// <summary>
        /// Gets or sets the condition.
        /// </summary>
        /// <value>The condition.</value>
        [BuildElementProperty("Condition", false, BuildElementPropertyType.Condition)]
        [Description("Optional attribute.\nCondition to be evaluated.")]
        [Category("MsBuild")]
        public string Condition {
            get { return _condition; }
            set {
                if (_condition != value) {
                    _condition = value;
                    OnPropertyChanged("Condition");
                }
            }
        }

        private string _itemName;

        /// <summary>
        /// Gets or sets the name of the item.
        /// </summary>
        /// <value>The name of the item.</value>
        [BuildElementProperty("ItemName", false, BuildElementPropertyType.String)]
        [Description("Either the PropertyName or ItemName attribute is required.\nThe item that receives the task's output parameter value. Your project can then reference the item with the @(ItemName) syntax. The item name can either be a new item name or a name that is already defined in the project.\nThis attribute cannot be used if PropertyName is also being used.")]
        [Category("MsBuild")]
        public string ItemName {
            get { return _itemName; }
            set {
                if (_itemName != value) {
                    _itemName = value;
                    OnPropertyChanged("ItemName");
                }
            }
        }

        private string _propertyName;

        /// <summary>
        /// Gets or sets the name of the property.
        /// </summary>
        /// <value>The name of the property.</value>
        [BuildElementProperty("PropertyName", false, BuildElementPropertyType.String)]
        [Description("Either the PropertyName or ItemName attribute is required.\nThe property that receives the task's output parameter value. Your project can then reference the property with the $(PropertyName) syntax. This property name can either be a new property name or a name that is already defined in the project.\nThis attribute cannot be used if ItemName is also being used.")]
        [Category("MsBuild")]
        public string PropertyName {
            get { return _propertyName; }
            set {
                if (_propertyName != value) {
                    _propertyName = value;
                    OnPropertyChanged("PropertyName");
                }
            }
        }

        private string _taskParameter;

        /// <summary>
        /// Gets or sets the task parameter.
        /// </summary>
        /// <value>The task parameter.</value>
        [BuildElementProperty("TaskParameter", true, BuildElementPropertyType.String)]
        [Description("Required attribute.\nThe name of the task's output parameter.")]
        [Category("MsBuild")]
        public string TaskParameter {
            get { return _taskParameter; }
            set {
                if (_taskParameter != value) {
                    _taskParameter = value;
                    OnPropertyChanged("TaskParameter");
                }
            }
        }

        /// <summary>
        /// Determines whether this instance is valid.
        /// </summary>
        /// <value></value>
        /// <returns>
        /// 	<c>true</c> if this instance is valid; otherwise, <c>false</c>.
        /// </returns>
        public override bool IsValid {
            get { throw new NotImplementedException(); }
        }

        /// <summary>
        /// Validates the specified recursive.
        /// </summary>
        /// <param name="recursive">if set to <c>true</c> [recursive].</param>
        /// <returns></returns>
        public override ReadOnlyCollection<ValidationResult> Validate(bool recursive) {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        public override object Clone() {
            OutputBuildElement newElement = base.Clone() as OutputBuildElement;

            if (this._condition != null) {
                newElement._condition = this._condition.Clone() as string;
            }
            if (this._itemName != null) {
                newElement._itemName = this._itemName.Clone() as string;
            }
            if (this._propertyName != null) {
                newElement._propertyName = this._propertyName.Clone() as string;
            }
            if (this._taskParameter != null) {
                newElement._taskParameter = this._taskParameter.Clone() as string;
            }

            return newElement;
        }
    }
}
